home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Resource for Source: C/C++
/
Resource for Source - C-C++.iso
/
misc_src
/
knowhow4
/
strtable.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-01
|
876b
|
38 lines
#include "strtable.h"
#define STEP 16 // Reallocation step
#define LSTEP 4 // LOG
KH_STRTABLE::KH_STRTABLE(int n, char** str)
{
strings = (char**)malloc((total = (n >> LSTEP << LSTEP) + STEP) * sizeof(char**));
for(int i = 0; i < n; i++)
{
if(str == NULL)
strings[i] = strdup("");
else
strings[i] = strdup(str[i]);
}
used = n;
}
////////////////////////////////
KH_STRTABLE::~KH_STRTABLE()
{
for(int i = 0; i < used; i++)
delete strings[i];
delete strings;
}
////////////////////////////////
int KH_STRTABLE::add(char* str)
{
if(used + 1 > total)
{
strings = (char**)realloc(strings, (total + STEP) * sizeof(char**));
total += STEP;
}
strings[used] = strdup(str);
used++;
return used;
}
////////////////////////////////